<?php


namespace Modules\Admin\Http\Controllers\Authorization\Role;


use Modules\Common\Models\AdminRole;
use Modules\Common\Util\Api;

class Sort
{
    /**
     * @Route(path=/api/admin/authorization/role/sort method=post)
     */
    public function index()
    {
        Api::validate(['role_id' => 'integer', 'up_down' => 'in:1,-1,99999,-99999']);
        $role = AdminRole::find(request('role_id'));
        switch (request('up_down')) {
            case 1:
                $role->moveOrderUp();
                break;
            case -1:
                $role->moveOrderDown();
                break;
            case 99999:
                $role->moveToStart();
                break;
            case -99999:
                $role->moveToEnd();
                break;
        }
        return Api::success();
    }


}
